/**
 * 用于介绍父类与子类的构造方法
 * 在Test1的基础上加上
 * 基础父类前，需要被初始化
 */

class Animal1 {

    public String name;
    public int age;
   /* public Animal1(){
        System.out.println("Animal1的无参构造方法被执行了");
    }
*/
    static {
       System.out.println("父类静态代码块被执行了");
   }
    {
        System.out.println("父类实例代码块被执行了");
    }
    public Animal1(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("父类构造方法被执行了");
    }
    public void sleep() {
        System.out.println(this.name+"正在睡觉");
    }
}
class Dog1 extends Animal1 {
    public String color;

  /*  public Dog1() {
        //super();默认会有super()语句
        System.out.println("Dog1中的无参构造方法被执行了");
    }*/

    static {
        System.out.println("子类静态代码块被执行了");
    }
    {
        System.out.println("子类实例代码块被执行了");
    }
    public Dog1(String name,int age,String color) {
        super(name,age);//需要调用父类构造方法，进行初始化
        this.color = color;//再初始化子类自己的成员变量
        System.out.println("子类构造方法被执行了");
    }
    public void eat() {
        System.out.println(this.name+"正在吃狗粮");
    }
    public void show() {
        System.out.println("name="+this.name+" "+"age="+this.age+" "+"color="+this.color);
    }
}

public class Test3 {
    public static void main(String[] args) {
        Dog1 dog = new Dog1("旺财",1,"黄色");
        System.out.println("-----------------------------");
        Dog1 dog2 = new Dog1("旺财",1,"黄色");
        //dog.name = "旺财";
       /* dog.show();
        dog.sleep();
        dog.eat();*/
    }
}


/*
class Animal1 {
    public String name;
    private int age;

    public Animal1(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public void sleep() {
        System.out.println(this.name+"正在睡觉");
    }
}
class Dog1 extends Animal1 {
    public String color;

    public void eat() {
        System.out.println(this.name+"正在吃狗粮");
    }
}
public class Test3 {
    public static void main(String[] args) {
        Dog1 dog = new Dog1();
        dog.sleep();
        dog.eat();
    }
}*/
